from datetime import datetime

from django.db import models

from apps.courses.models import Course
from apps.users.models import UserProfile, BaseModel


class UserAsk(BaseModel):
    """用户咨询表"""
    name = models.CharField("姓名", max_length=20)
    mobile = models.CharField("手机", max_length=11)
    course_name = models.CharField("课程名", max_length=50)

    class Meta:
        verbose_name = "用户咨询"
        verbose_name_plural = verbose_name

    def __str__(self):
        return "{name}_{course}({mobile})".format(name=self.name, course=self.course_name,
                                                  mobile=self.mobile)


class UserMessage(BaseModel):
    """用户消息表"""
    user = models.IntegerField("接受用户", default=0)
    message = models.CharField("消息内容", max_length=500)
    has_read = models.BooleanField("是否已读", default=False)

    class Meta:
        verbose_name = "用户消息"
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.message


class CourseComments(BaseModel):
    """课程评论表"""
    user = models.ForeignKey(UserProfile, verbose_name="用户", on_delete=models.CASCADE)
    course = models.ForeignKey(Course, verbose_name="课程", on_delete=models.CASCADE)
    comments = models.CharField("评论", max_length=200)

    class Meta:
        verbose_name = "课程评论"
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.comments


class UserCourse(BaseModel):
    """用户课程表"""
    user = models.ForeignKey(UserProfile, verbose_name="用户", on_delete=models.CASCADE)
    course = models.ForeignKey(Course, verbose_name="课程", on_delete=models.CASCADE)

    class Meta:
        verbose_name = "用户课程"
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.course.name


class UserFavorite(BaseModel):
    """用户收藏表"""
    FAV_TYPE = (
        (1, "课程"),
        (2, "课程机构"),
        (3, "讲师")
    )

    user = models.ForeignKey(UserProfile, verbose_name="用户", on_delete=models.CASCADE)
    fav_id = models.IntegerField("数据id", default=0)
    fav_type = models.IntegerField(verbose_name="收藏类型", choices=FAV_TYPE, default=1)

    class Meta:
        verbose_name = "用户收藏"
        verbose_name_plural = verbose_name

    def __str__(self):
        return "{user}_{id}".format(user=self.user.username,
                                    id=self.fav_id)
